Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support multi receiver by matchLabels #482

Merged
merged 3 commits into from
Mar 23, 2023

Conversation

raffis
Copy link
Contributor

@raffis raffis commented Mar 6, 2023

Current situation

At the moment one has to reference each resource by name for a webhook receiver.
While spec.resources actually is a CrossNamespaceObjectReference which supports matchLabels. However this is not implemented in the internal handling of the receiver. What I like to achieve is basically trigger a reconcile for multiple HelmCharts matching a certain label (or just all of them in a specific namespace).

This currently is unsupported in the reconcile logic while it is supported in the api:

apiVersion: notification.toolkit.fluxcd.io/v1beta2
kind: Receiver
metadata:
  name: ghcr-receiver
  namespace: flux-system
spec:
  events:
  - package
  resources:
  - apiVersion: source.toolkit.fluxcd.io/v1beta2
    kind: HelmChart
    matchLabels:
      registry: ghcr
    name: '*'
  secretRef:
    name: github-webhook-token
  type: github

Background

I like to send a webhook from github for helm packages published in ghcr. The receiver should reconcile all (or matching helm charts by label) charts and trigger a reconcile.
What I am trying to avoid is set a very low interval but instead reconcile a helmrelease immediately if a new version is published via webhook.
This works perfectly fine already but I would need to specify each chart manually in the list of resources.

Proposal

Support matchLabels and * as name the same way as this is already supported for Alerts in the notification-controller.

@raffis raffis force-pushed the feat-receiver-by-labels branch from f8b1720 to 3a7a8ca Compare March 10, 2023 14:16
@raffis raffis requested a review from somtochiama March 10, 2023 14:17
Copy link
Member

@makkes makkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how this is supposed to work. The .name field is still mandatory and this PR doesn't change the way it is handled. The PR description says you can set name to * the same way we support it with Alerts but the commits don't back this up.

In fact, name is still used to fetch a single resource and in addition matchLabels is taken into account as well.

@raffis
Copy link
Contributor Author

raffis commented Mar 13, 2023

I don't understand how this is supposed to work. The .name field is still mandatory and this PR doesn't change the way it is handled. The PR description says you can set name to * the same way we support it with Alerts but the commits don't back this up.

In fact, name is still used to fetch a single resource and in addition matchLabels is taken into account as well.

Hey please align on your side and decide what you want, #482 (comment)

@raffis raffis requested review from makkes and removed request for somtochiama March 13, 2023 10:34
@makkes
Copy link
Member

makkes commented Mar 13, 2023

I don't understand how this is supposed to work. The .name field is still mandatory and this PR doesn't change the way it is handled. The PR description says you can set name to * the same way we support it with Alerts but the commits don't back this up.
In fact, name is still used to fetch a single resource and in addition matchLabels is taken into account as well.

Hey please align on your side and decide what you want, #482 (comment)

I see 2 issues with the details of this PR:

  1. The .spec.resources.name field is required so it can never be empty.
  2. Even if we changed it back to * as a special case (sorry, haven't looked at the resolved comments) the receiver handler would still try to get an object of that name and fail.

A solution would be to accept * as a name and treat it specially. However, there's still two cases that would need to be covered:

  • .spec.resources.name == * and .spec.resources.matchLabels is missing.
  • .spec.resources.name == * and .spec.resources.matchLabels is present.

But then the question arises of how we handle .spec.resources.name not being * and .spec.resources.matchLabels being present. This case doesn't make sense and IMHO should be prevented at the validation level.

@raffis
Copy link
Contributor Author

raffis commented Mar 13, 2023

I don't understand how this is supposed to work. The .name field is still mandatory and this PR doesn't change the way it is handled. The PR description says you can set name to * the same way we support it with Alerts but the commits don't back this up.
In fact, name is still used to fetch a single resource and in addition matchLabels is taken into account as well.

Hey please align on your side and decide what you want, #482 (comment)

I see 2 issues with the details of this PR:

1. The `.spec.resources.name` field is required so it can never be empty.

2. Even if we changed it back to `*` as a special case (sorry, haven't looked at the resolved comments) the receiver handler would still try to get an object of that name and fail.

I will change it back then. That's what I suggested in the first place.

A solution would be to accept * as a name and treat it specially. However, there's still two cases that would need to be covered:

* `.spec.resources.name` == `*` and `.spec.resources.matchLabels` is missing.

Either we can can change it so if no matchLabels are set and its * it would select all resources. Or if no change it would just fallback to select by name which would fail to get a resource since there is none named *. I would say first one.

* `.spec.resources.name` == `*` and `.spec.resources.matchLabels` is present.

Well thats the case which is covered if I change it back how it was initially.

But then the question arises of how we handle .spec.resources.name not being * and .spec.resources.matchLabels being present. This case doesn't make sense and IMHO should be prevented at the validation level.

This would require a validation hook I reckon. But this is also possible in Alert actually. You currently can set match labels while name is not *.

@somtochiama
Copy link
Member

@makkes My bad, I suggested checking for an empty name field in my last review, forgetting that the name was required.
Thanks @raffis for reverting the change

@raffis raffis requested review from somtochiama and removed request for makkes March 14, 2023 13:42
Copy link
Member

@makkes makkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much better now. Just some suggestions and please also update docs/api/notification.md to reflect the changes around the semantics of .spec.resources.

@raffis raffis force-pushed the feat-receiver-by-labels branch from 8f69751 to 1ae0f47 Compare March 16, 2023 09:46
@raffis raffis requested review from makkes and removed request for somtochiama March 16, 2023 11:29
Copy link
Member

@makkes makkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a last nit. Otherwise lgtm.

@raffis raffis requested a review from makkes March 20, 2023 07:47
Copy link
Member

@makkes makkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have everything in place right now. Good job, @raffis. 🎖️

Please squash all your commits into one, then I'll make sure to get it merged.

@raffis raffis force-pushed the feat-receiver-by-labels branch from 036a521 to 57f62f4 Compare March 20, 2023 08:12
@raffis
Copy link
Contributor Author

raffis commented Mar 20, 2023

I think we have everything in place right now. Good job, @raffis. medal_military

Please squash all your commits into one, then I'll make sure to get it merged.

Done, thx for the review 🥇

@makkes
Copy link
Member

makkes commented Mar 20, 2023

@somtochiama mind to take a final look, please? 🙏🏻

@makkes makkes added the hold Issues and pull requests put on hold label Mar 20, 2023
@makkes
Copy link
Member

makkes commented Mar 20, 2023

Holding for next minor release.

@makkes makkes added this to the 0.34 milestone Mar 20, 2023
@makkes makkes added the enhancement New feature or request label Mar 20, 2023
@makkes makkes added the area/receiver Webhook receiver related issues and PRs label Mar 20, 2023
Copy link
Member

@somtochiama somtochiama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Thanks @raffis 🚀

Copy link
Member

@makkes makkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry @raffis but I need to ask for one additional change: Please document the changed API in https://github.com/fluxcd/notification-controller/blob/main/docs/spec/v1beta2/receivers.md#resources. The content of that page is published at https://fluxcd.io/flux/components/notification/receiver/ so we need give clear guidance on how to use matchLabels.

Signed-off-by: Raffael Sahli <[email protected]>
Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @raffis 🏅

@stefanprodan stefanprodan requested a review from makkes March 23, 2023 09:54
@makkes makkes merged commit f8ab99e into fluxcd:main Mar 23, 2023
@makkes makkes removed the hold Issues and pull requests put on hold label Mar 23, 2023
makkes pushed a commit that referenced this pull request Mar 27, 2023
This has been introduced in #482 but we actually want this feature to
only be available in v1 of the API. A follow-up PR will re-add this to
the v1 API.

Signed-off-by: Max Jonas Werner <[email protected]>
makkes pushed a commit that referenced this pull request Mar 27, 2023
This has been introduced in #482 but we actually want this feature to
only be available in v1 of the API. A follow-up PR will re-add this to
the v1 API.

Signed-off-by: Max Jonas Werner <[email protected]>
makkes pushed a commit that referenced this pull request Mar 27, 2023
This functionality has been implemented in #482 but we only want to
expose it in v1 of the API.

Signed-off-by: Max Jonas Werner <[email protected]>
makkes pushed a commit that referenced this pull request Mar 27, 2023
This functionality has been implemented in #482 but we only want to
expose it in v1 of the API.

Signed-off-by: Max Jonas Werner <[email protected]>
makkes pushed a commit that referenced this pull request Mar 30, 2023
This functionality has been implemented in #482 but we only want to
expose it in v1 of the API.

Signed-off-by: Max Jonas Werner <[email protected]>
alekspog pushed a commit to alekspog/notification-controller that referenced this pull request Mar 30, 2023
This has been introduced in fluxcd#482 but we actually want this feature to
only be available in v1 of the API. A follow-up PR will re-add this to
the v1 API.

Signed-off-by: Max Jonas Werner <[email protected]>
alekspog pushed a commit to alekspog/notification-controller that referenced this pull request Mar 30, 2023
This functionality has been implemented in fluxcd#482 but we only want to
expose it in v1 of the API.

Signed-off-by: Max Jonas Werner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/receiver Webhook receiver related issues and PRs enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants